<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/10/15 11:23
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class GptPlatform extends Platform
{
    public static function getName(): string
    {
        return 'GPT';
    }

    public static function getFlag(): string
    {
        return 'gpt';
    }

    public static function models(): array
    {
        return [
            'gpt-3.5-turbo' => 'GPT-3.5-Turbo',
            'gpt-4'         => 'GPT-4',
            'gpt-4-turbo'   => 'GPT-4 Turbo',
            'gpt-4o'        => 'GPT-4o',
            'gpt-4o-mini'   => 'GPT-4o-mini',
        ];
    }

    public function getConfigForm(Model $model = null): array
    {
        return [
            [
                "label" => "API接口",
                "prop"  => "config.base_url",
                "value" => $model['config']['base_url'] ?? '',
                "intro" => "API接口地址，默认为：https://api.openai.com/v1<br>默认地址无法通信，可尝试使用第三方转发接口。",
            ],
            ...parent::getConfigForm($model),
            [
                "label" => "frequency_penalty",
                "prop"  => "config.frequency_penalty",
                "value" => $model['config']['frequency_penalty'] ?? '',
                "intro" => "重复惩罚，用通过对已生成的token增加惩罚，减少重复生成的现象。取值范围[-2.0, 2.0]。",
            ],
            [
                "label" => "presence_penalty",
                "prop"  => "config.presence_penalty",
                "value" => $model['config']['presence_penalty'] ?? '',
                "intro" => "存在惩罚，介于-2.0到2.0之间的数字。较高的数值会使输出更加随机，而较低的数值会使其更加集中和确定。取值范围[0.01, 1.00]。建议该参数和top_p只设置1个。",
            ],
            [
                "label" => "max_completion_tokens",
                "prop"  => "config.max_completion_tokens",
                "value" => $model['config']['max_completion_tokens'] ?? '',
                "intro" => "模型最大输出token数"
            ],
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "温度，较高的值（如0.8）将使输出更加随机，而较低的值（如0.2）将使输出更加集中和确定。取值范围[0,2]。建议该参数和top_p只设置1个。",
            ],
            [
                "label" => "top_p",
                "prop"  => "config.top_p",
                "value" => $model['config']['top_p'] ?? '',
                "intro" => "多样性，影响输出文本的多样性，取值越大，生成文本的多样性越强。取值范围[0, 1.0]。建议该参数和temperature只设置1个。"
            ],
        ];
    }
}